package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbItemCatMapper;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.pojo.TbItemCatExample;
import com.dongdongshop.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class ItemCatServiceImpl implements ItemCatService {

    @Autowired
    private TbItemCatMapper tbItemCatMapper;

    @Override
    public List<TbItemCat> findAll(Long parentId) {
        List<TbItemCat> catList = tbItemCatMapper.selectById(parentId);
        return catList;
    }

    @Override
    public boolean insert(TbItemCat tbItemCat) {
        int i = tbItemCatMapper.insertSelective(tbItemCat);
        return i > 0;
    }

    @Override
    public TbItemCat selectById(Long id) {
        TbItemCat tbItemCat = tbItemCatMapper.selectByPrimaryKey(id);
        return tbItemCat;
    }

    @Override
    public boolean updateInfo(TbItemCat tbItemCat) {
        int i = tbItemCatMapper.updateByPrimaryKeySelective(tbItemCat);
        return i > 0;
    }

    @Override
    public List<TbItemCat> selectByItemCatByParentId(long l) {
        TbItemCatExample tbItemCatExample = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = tbItemCatExample.createCriteria();
        criteria.andParentIdEqualTo(l);
        return tbItemCatMapper.selectByExample(tbItemCatExample);
    }

    @Override
    public List<TbItemCat> getItemTypeId(Long pid) {
        List<TbItemCat> list = tbItemCatMapper.getItemTypeId(pid);
        return list;
    }
}
